package com.fbs.framework.exception;

/*
创建者:虾米糖
*/

import com.fbs.framework.common.ResponseData;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(TokenException.class)
    @ResponseBody
    public ResponseData tokenException(HttpServletRequest request, TokenException e){
        log.error("error path:{} e:",request.getRequestURI(),e);
        ResponseData responseData = new ResponseData();

            responseData.setCode(e.getCode());
            responseData.setMsg(e.getMsg());

        return responseData ;

    }

    @ExceptionHandler(ParamException.class)
    @ResponseBody
    public ResponseData paramException(HttpServletRequest request ,ParamException e) {
        log.info("error path:{} e",request.getRequestURI(),e);
        ResponseData responseData = new ResponseData();
        responseData.setCode(e.getCode());
        responseData.setMsg(e.getMsg());
        return responseData;
    }
}
